/*
Miranda IM for Windows Search

Copyright (C) 2012 Nikolay Raspopov

This program is free software; you can redistribute it and/or
modify it under the terms of the GNU General Public License
as published by the Free Software Foundation; either version 2
of the License, or (at your option) any later version.

This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
GNU General Public License for more details.

You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
*/

#pragma once

#include "MirandaSearch.h"

// CMirandaAccessor

class ATL_NO_VTABLE CMirandaAccessor :
	public CComObjectRootEx< CComMultiThreadModel >,
	public CComCoClass< CMirandaAccessor, &CLSID_MirandaAccessor >,
	public IUrlAccessor4
//	public IOpLockStatus
{
public:
	CMirandaAccessor();

DECLARE_REGISTRY_RESOURCEID(IDR_MIRANDAACCESSOR)

BEGIN_COM_MAP(CMirandaAccessor)
	COM_INTERFACE_ENTRY2(IUrlAccessor, IUrlAccessor2)
	COM_INTERFACE_ENTRY2(IUrlAccessor2, IUrlAccessor3)
	COM_INTERFACE_ENTRY2(IUrlAccessor3, IUrlAccessor4)
	COM_INTERFACE_ENTRY(IUrlAccessor4)
//	COM_INTERFACE_ENTRY(IOpLockStatus)
END_COM_MAP()

DECLARE_PROTECT_FINAL_CONSTRUCT()

	HRESULT FinalConstruct();
	void FinalRelease();

	STDMETHOD(Init)(const CString& sURL);

protected:
	URLLevel			m_nURLLevel;
	CString				m_sURL;				// Original full URL: "miranda://{SID}/[contact[/event]]"
	CString				m_sRelativeURL;		// Relative URL: "/[contact[/event]]"

    // IUrlAccessor
    STDMETHOD(AddRequestParameter)(PROPSPEC *pSpec, PROPVARIANT *pVar);
    STDMETHOD(GetDocFormat)(__out_ecount_part(dwSize, *pdwLength) WCHAR wszDocFormat[], DWORD dwSize, __out DWORD *pdwLength);
    STDMETHOD(GetCLSID)(__out CLSID *pClsid);
    STDMETHOD(GetHost)(__out_ecount_part(dwSize, *pdwLength) WCHAR wszHost[], DWORD dwSize, __out DWORD *pdwLength);
    STDMETHOD(IsDirectory)();
    STDMETHOD(GetSize)(__out ULONGLONG *pllSize);
    STDMETHOD(GetLastModified)(__out FILETIME *pftLastModified);
    STDMETHOD(GetFileName)(__out_ecount_part(dwSize, *pdwLength) WCHAR wszFileName[], DWORD dwSize, __out DWORD *pdwLength);
    STDMETHOD(GetSecurityDescriptor)(__out_ecount_full(dwSize) BYTE *pSD, DWORD dwSize, __out DWORD *pdwLength);
    STDMETHOD(GetRedirectedURL)(__out_ecount_part(dwSize, *pdwLength) WCHAR wszRedirectedURL[], DWORD dwSize, __out DWORD *pdwLength);
    STDMETHOD(GetSecurityProvider)(__out CLSID *pSPClsid);
    STDMETHOD(BindToStream)(__deref_out IStream **ppStream);
    STDMETHOD(BindToFilter)(__deref_out IFilter **ppFilter);

    // IUrlAccessor2
    STDMETHOD(GetDisplayUrl)(__out_ecount_part(dwSize, *pdwLength) WCHAR wszDocUrl[], DWORD dwSize, __out DWORD *pdwLength);
    STDMETHOD(IsDocument)();
    STDMETHOD(GetCodePage)(__out_ecount_part(dwSize, *pdwLength) WCHAR wszCodePage[], DWORD dwSize, __out DWORD *pdwLength);

    // IUrlAccessor3
    STDMETHOD(GetImpersonationSidBlobs)(__RPC__in LPCWSTR pcwszURL, __RPC__out DWORD *pcSidCount, __RPC__deref_out_opt BLOB **ppSidBlobs);

	// IUrlAccessor4
    STDMETHOD(ShouldIndexItemContent)(__RPC__out BOOL *pfIndexContent);
    STDMETHOD(ShouldIndexProperty)(__RPC__in REFPROPERTYKEY key, __RPC__out BOOL *pfIndexProperty);

	// IOpLockStatus
    //STDMETHOD(IsOplockValid)(__out  BOOL *pfIsOplockValid);        
    //STDMETHOD(IsOplockBroken)(__out  BOOL *pfIsOplockBroken);        
    //STDMETHOD(GetOplockEventHandle)(__deref_out  HANDLE *phOplockEv);
};

OBJECT_ENTRY_AUTO(__uuidof(MirandaAccessor), CMirandaAccessor)
